package ustc.xiaoyang.karl.binarysearch;

public class ValidPerfectSquareNumber367 {
    public static void main(String[] args) {

        System.out.println(new ValidPerfectSquareNumber367().isPerfectSquare(16));
    }
    public boolean isPerfectSquare(int num) {
        int left = 1, right = num;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if((long) mid * mid > num){
                right = mid - 1;
            } else if ((long)mid * mid <num) {
                left = mid + 1;
            }else{
                return true;
            }
        }
        return false;
    }
}
